﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms;

namespace WebResourcesManager
{
    // Create a node sorter that implements the IComparer interface.
    public class NodeSorter : IComparer
    {
        // Compare the length of the strings, or the strings
        // themselves, if they are the same length.
        public int Compare(object x, object y)
        {
            TreeNode tx = x as TreeNode;
            TreeNode ty = y as TreeNode;

            if (tx.ImageIndex == ty.ImageIndex)
            {
                return string.Compare(tx.Text, ty.Text);
            }
            else if (tx.ImageIndex == 0)
            {
                return -1;
            }
            else if (tx.ImageIndex == 1 && tx.ImageIndex < ty.ImageIndex)
            {
                return -1;
            }
            else if (ty.ImageIndex == 1 && ty.ImageIndex < tx.ImageIndex)
            {
                return 1;
            }
            else
                return string.Compare(tx.Text, ty.Text);
        }
    }


}
